#include "stdafx.h"
#include "CalcDifference.h"
#include "includeIpp.h"

DifferenceInfo CalcDifferenceInfo(FTLib::IBitmapData* pB1, FTLib::IBitmapData* pB2)
{
	// precondition: pB1 and pB2 have the same size and pixeltype=float32
	DifferenceInfo info;

	auto diffBitmap = FTLib::CreateBitmapStd(pB1->GetPixelType(), pB1->GetWidth(), pB1->GetHeight());

	auto bli1 = pB1->Lock();
	auto bli2 = pB2->Lock();
	auto bliDst = diffBitmap->Lock();

	IppiSize size = { pB1->GetWidth(), pB1->GetHeight() };
	ippiAbsDiff_32f_C1R((Ipp32f*)bli1.ptrDataRoi, bli1.pitch, (Ipp32f*)bli2.ptrDataRoi, bli2.pitch, (Ipp32f*)bliDst.ptrDataRoi, bliDst.pitch, size);
	ippiMean_StdDev_32f_C1R((Ipp32f*)bliDst.ptrDataRoi, bliDst.pitch, size, &info.meanOfDifferences, &info.stdDevOfDifferences);

	ippiMinMax_32f_C1R((Ipp32f*)bliDst.ptrDataRoi, bliDst.pitch, size, &info.minDifference, &info.maxDifference);

	return info;
}